package com.boyi.cycling_master.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.boyi.cycling_master.R;
import com.boyi.cycling_master.bean.ResponseBean;
import com.boyi.cycling_master.common.PostParams;
import com.boyi.cycling_master.common.SnackUtil;
import com.boyi.cycling_master.https.utils.UserInfoRetrofit;
import com.boyi.cycling_master.ui.base.BaseToolBarActivity;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author Lee_Mofeel
 * @version 1.0
 * @date 2017/7/27/027 10:14
 * @Description 用户意见反馈
 */

public class UserIdeaActivity extends BaseToolBarActivity {
    @BindView(R.id.edt_user_idea_content)
    EditText edtUserIdeaContent;
    @BindView(R.id.tv_btn_to_next)
    TextView tvBtnToNext;

    @Override
    public int getContentViewId() {
        return R.layout.activity_user_idea;
    }

    @Override
    public void initLogic() {

    }

    @Override
    public void getBundleExtras(Bundle bundle) {

    }

    @Override
    public String pageTitle() {
        return "意见反馈";
    }


    @OnClick(R.id.tv_btn_to_next)
    public void onViewClicked() {
        String content = edtUserIdeaContent.getText().toString();
        if(TextUtils.isEmpty(content)){
            SnackUtil.SnackShort(edtUserIdeaContent,"请输入您的意见 我们会尽快处理");
        }else{
            Map<String,String> map = new HashMap<>();
            map.put("fbContext",content);
            UserInfoRetrofit.getInstance().submitUserIdea(new Callback<ResponseBean>() {
                @Override
                public void onResponse(Call<ResponseBean> call, Response<ResponseBean> response) {
                    if(response.body() == null)
                        return;
                    SnackUtil.SnackShort(edtUserIdeaContent,response.body().getResultMessage());
                    if(response.body().getResultCode().equals("200")){
                        finish();
                    }
                }

                @Override
                public void onFailure(Call<ResponseBean> call, Throwable t) {

                }
            }, PostParams.makeRequestBody(map));
        }
    }
}
